package com.atlyn.web;

import com.atlyn.bean.Teacher;
import com.atlyn.dao.LoginDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class TLoginServlet extends HttpServlet {
    LoginDao loginDao = new LoginDao();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求的参数
        int username = Integer.parseInt(request.getParameter("t_username"));
        String password = request.getParameter("t_password");
        System.out.println(username + password);
        Teacher teacher = loginDao.tLogin(username,password);
        System.out.println(loginDao.tLogin(username,password));
        if (teacher != null) {
            request.setAttribute("tid",username);
            request.setAttribute("teacher",teacher);
            request.getRequestDispatcher("/tHome.jsp").forward(request,response);
        }else {
            System.out.println("登录失败！");
            //跳回注册页面
            request.getRequestDispatcher("/切换.html").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
